var util = {
	logId: "#log",
	pad0(n) {
		return n > 9 ? n : "0" + n;
	},
	getTime() {
		let now = new Date();
		return this.pad0(now.getHours()) + ":" + this.pad0(now.getMinutes()) + ":" + this.pad0(now.getSeconds());
	},
	sleep(ms) {
		let from = new Date();
		while (new Date() - from < ms);
	},
	clearLog() {
		$(this.logId).empty();
		return this;
	},
	appendLog(text) {
		text = this.getTime() + " " + text;
		$(this.logId).append(`<li>${text}</li>`);
		return this;
	},
	isEmail(text) {
		var pattern = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
		return pattern.test(text);
	},
	isPhone(text) {
		var pattern = /^(13|14|15|18)\d{9}$/;
		return pattern.test(text);
	},
	waitDOM(selector, interval) {
		if (!interval) interval = 1000;
		return new Promise((resolve, reject) => {
			let check = () => {
				if ($(selector).length > 0) {
					resolve();
				} else {
					setTimeout(check, interval);
				}
			}
			check();
		});
	}
};
